package com.mrogrape.notepad.activity.view;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.ArrayList;
import java.util.List;

import javax.swing.BorderFactory;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JPopupMenu;
import javax.swing.JToolBar;
import javax.swing.KeyStroke;
import javax.swing.WindowConstants;

import com.jidesoft.plaf.LookAndFeelFactory;
import com.jidesoft.swing.JideButton;
import com.jidesoft.swing.JideMenu;
import com.jidesoft.swing.JideSplitButton;
import com.mrogrape.notepad.activity.MainFrame;
import com.mrogrape.notepad.activity.action.MainFrameActionFactory;
import com.mrogrape.notepad.activity.action.item.CloseAllMenuItemAction;
import com.mrogrape.notepad.activity.action.item.CloseMenuItemAction;
import com.mrogrape.notepad.activity.action.item.CloseOthersMenuItemAction;
import com.mrogrape.notepad.activity.action.item.FilePropertyMenuItemAction;
import com.mrogrape.notepad.activity.action.item.FindAndReplaceMenuItemAction;
import com.mrogrape.notepad.activity.action.item.NewHtmlEditorMenuItemAction;
import com.mrogrape.notepad.activity.action.item.NewJavaEditorMenuItemAction;
import com.mrogrape.notepad.activity.action.item.NewPlainTextMenuItemAction;
import com.mrogrape.notepad.activity.action.item.NewSQLEditorMenuItemAction;
import com.mrogrape.notepad.activity.action.item.NewXMLEditorMenuItemAction;
import com.mrogrape.notepad.activity.action.item.RedoMenuItemAction;
import com.mrogrape.notepad.activity.action.item.ReloadMenuItemAction;
import com.mrogrape.notepad.activity.action.item.SaveAsMenuItemAction;
import com.mrogrape.notepad.activity.action.item.UndoMenuItemAction;
import com.mrogrape.notepad.activity.entity.ViewSettings;
import com.mrogrape.notepad.data.ViewContext;
import com.mrogrape.notepad.resource.Icons;
import com.mrogrape.notepad.resource.Settings;
import com.mrogrape.notepad.ui.ClosableTabPanel;
import com.mrogrape.notepad.ui.ClosableTabbedPane;
import com.mrogrape.notepad.ui.ComponentFactory;
import com.mrogrape.notepad.ui.editor.TextEditor;
import com.mrogrape.notepad.ui.library.LibraryPane;


public abstract class MainFrameView extends JFrame implements MainFrame{

	/** serialVersionUID */
	private static final long serialVersionUID = 1L;

	static{

		LookAndFeelFactory.installDefaultLookAndFeelAndExtension();
	}

	public MainFrameView(){

		this.initializeComponents();
		this.applyPreferences();
	}

	@Override
	public void showFrame() {

		this.setVisible(true);
	}

	@Override
	public void closeWorkPanel(ClosableTabPanel panel) {

		if(!this.contentPane.getAllComponents().contains(panel)){

			return;
		}

		boolean result = panel.onClose();
		if(result){

			this.contentPane.removeTab(panel);
		}
	}

	/**
	 * 获取全部的文本编辑器。
	 * 
	 * @return
	 */
	@Override
	public List<TextEditor> getAllTextEditors(){

		List<TextEditor> editors = new ArrayList<TextEditor>();

		List<ClosableTabPanel> comps =  this.contentPane.getAllComponents();

		for(ClosableTabPanel c : comps){

			if(c instanceof TextEditor){
				editors.add((TextEditor) c);
			}
		}

		return editors;
	}

	@Override
	public List<ClosableTabPanel> getAllWorkPanels() {

		return this.contentPane.getAllComponents();
	}

	/**
	 * 获取当前活动的文本编辑器，如果当前活动的面板不是文本编辑器，则返回null。
	 * 
	 * @return
	 */
	@Override
	public TextEditor getCurrentTextEditor(){

		ClosableTabPanel c = this.contentPane.getSelectedComponent();

		if(c instanceof TextEditor){

			return (TextEditor) c;
		}

		return null;
	}


	@Override
	public ClosableTabPanel getCurrentWorkPanel() {

		return this.contentPane.getSelectedComponent();
	}


	@Override
	public void setSelectedWorkPanel(int index) {

		this.contentPane.setSelectedComponentIndex(index);
	}

	@Override
	public void setSelectedWorkPanel(ClosableTabPanel workPanel) {


		this.contentPane.setSelectedComponent(workPanel);
	}



	@Override
	public boolean isToolbarVisible() {

		return this.toolbar.isVisible();
	}

	@Override
	public void setToolbarVisible(boolean b) {

		this.toolbar.setVisible(b);
	}
	
	@Override
	public boolean isLibraryPaneVisible() {

		return this.libraryPane != null && this.libraryPane.isVisible();
	}

	@Override
	public void setLibraryPaneVisible(boolean b) {
		
		
		if(b && this.libraryPane == null){
			this.libraryPane = ViewContext.getLibraryPane();
			this.libraryPane.setBorder(BorderFactory.createEtchedBorder());
			this.libraryPane.buildStructure();
			this.add(this.libraryPane, BorderLayout.WEST);
			this.validate();
			this.repaint();
		}
		else if(this.libraryPane != null){
			this.libraryPane.setVisible(b);
		}
	}

	/**
	 * 添加一个新选项卡。
	 * @param tab
	 */
	protected void addNewTab(ClosableTabPanel tab){

		this.contentPane.addTab(tab);
	}

	/**
	 * 获取主面板。
	 * 
	 * @return
	 */
	protected ClosableTabbedPane getTabbedPane(){

		return this.contentPane;
	}


	/** 窗口关闭事件处理器。 */
	protected abstract void thiswindowClosing(WindowEvent e);

	/** 打开文件菜单项的事件处理器 */
	protected abstract void openMntmActionPerformed(ActionEvent e);

	/** 打开文件按钮的事件处理器 */
	protected abstract void openBtnActionPerformed(ActionEvent e);

	/** 保存文件菜单项事件处理器 */
	protected abstract void saveMntmActionPerformed(ActionEvent arg0);

	/** 保存文件按钮事件处理器 */
	protected abstract void saveBtnActionPerformed(ActionEvent arg0);

	/** 退出菜单事件处理器 */
	protected abstract void exitMntmActionPerformed(ActionEvent arg0);

	/** 新建按钮 */
	protected abstract void newMenuBtnActionPerformed(ActionEvent e);

	/** 保存全部 */
	protected abstract void saveAllMntmActionPerformed(ActionEvent arg0);

	private void initializeComponents(){

		
		super.setTitle("JNotepad");
		super.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
		super.setIconImages(Icons.Frame.MAIN_FRAME);

		
		this.toolbar = new JToolBar();
		this.getContentPane().add(this.toolbar,BorderLayout.NORTH);
		JPanel contentPanel = (JPanel)this.getContentPane();
		contentPanel.setTransferHandler(ViewContext.getMainFrameTransferHander());

		this.newMenuBtn = new JideSplitButton();
		this.newMenuBtn.setIcon(Icons.Small.NEW);
		this.newMenuBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				MainFrameView.this.newMenuBtnActionPerformed(arg0);
			}
		});
		this.newMenuBtn.setText("New");
		this.toolbar.add(this.newMenuBtn);

		this.newPlainTextMntm = new JMenuItem(new NewPlainTextMenuItemAction(this));
		this.newMenuBtn.add(this.newPlainTextMntm);

		this.newJavaMntm = new JMenuItem(new NewJavaEditorMenuItemAction(this));
		this.newMenuBtn.add(this.newJavaMntm);

		this.newXmlMntm = new JMenuItem(new NewXMLEditorMenuItemAction(this));
		this.newMenuBtn.add(this.newXmlMntm);

		this.newHtmlMntm = new JMenuItem(new NewHtmlEditorMenuItemAction(this));
		this.newMenuBtn.add(this.newHtmlMntm);

		this.newSqlMntm = new JMenuItem(new NewSQLEditorMenuItemAction(this));
		this.newMenuBtn.add(this.newSqlMntm);

		this.openBtn = new JideButton();
		this.openBtn.setText("Open");
		this.openBtn.setIcon(Icons.Small.OPEN);
		this.openBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				MainFrameView.this.openBtnActionPerformed(e);
			}
		});
		this.toolbar.add(this.openBtn);

		this.saveBtn = new JideButton();
		this.saveBtn.setText("Save");
		this.saveBtn.setIcon(Icons.Small.SAVE);
		this.saveBtn.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				MainFrameView.this.saveBtnActionPerformed(e);
			}
		});
		this.toolbar.add(this.saveBtn);

		this.menuBar = new JMenuBar();
		this.setJMenuBar(this.menuBar);

		this.menuBar.add(this.createFileMenu());
		this.menuBar.add(this.createEditMenu());
		this.menuBar.add(this.createViewMenu());

		this.toolsMenu = new JideMenu("Tools");
		this.menuBar.add(this.toolsMenu);

//		this.favoriteMenu = new JideMenu("Favorite");
//		this.menuBar.add(this.favoriteMenu);

		this.helpMenu = new JideMenu("Help");
		this.menuBar.add(this.helpMenu);
		
		this.updateLogsMntm = new JMenuItem(MainFrameActionFactory.fetchUpdateLogsMenuItemAction());
		this.helpMenu.add(this.updateLogsMntm);

		this.aboutMntm = new JMenuItem("About JNotepad...");
		this.helpMenu.add(this.aboutMntm);
		
		this.contentPane = new ClosableTabbedPane();
		this.getContentPane().add(this.contentPane, BorderLayout.CENTER);

		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {
				MainFrameView.this.thiswindowClosing(e);
			}
		});

		this.getContentPane().add(ViewContext.getStatusBar(), BorderLayout.SOUTH);
		this.contentPane.addChangeListener(ViewContext.getStatusBar());

		// 库视图
		if(this.viewSettings.getShowLibraryView()){
			this.libraryPane = ViewContext.getLibraryPane();
			this.libraryPane.setBorder(BorderFactory.createEtchedBorder());
			this.add(this.libraryPane, BorderLayout.WEST);
		}
		
		this.pack();
	}

	
	private void applyPreferences(){
		
		// 主窗体大小
		this.setSize(Settings.getSettings().getMainFrameSize());
		// 主窗体状态
		this.setExtendedState(Settings.getSettings().getMainFrameState());
		// 是否显示工具栏
		this.setToolbarVisible(Settings.getSettings().isShowToolbar());

		// 是否显示状态栏
		ViewContext.getStatusBar().setVisible(this.viewSettings.isStateBarVisible());
	}

	/**
	 * 创建文件菜单
	 * @return
	 */
	private JMenu createFileMenu(){

		this.fileMenu = new JideMenu("File");
		this.menuBar.add(this.fileMenu);

		this.newMenu = new JideMenu("New");
		this.newMenu.setIcon(Icons.Small.NEW);
		this.fileMenu.add(this.newMenu);

		this.plainTextMutm = new JMenuItem(new NewPlainTextMenuItemAction(this));
		this.plainTextMutm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));
		this.newMenu.add(this.plainTextMutm);

		this.newMenu.add(ComponentFactory.createMenuSeparator());

		this.newJavaEditorMntm = new JMenuItem(new NewJavaEditorMenuItemAction(this));
		this.newMenu.add(this.newJavaEditorMntm);

		this.newSqlEditorMntm = new JMenuItem(new NewXMLEditorMenuItemAction(this));
		this.newMenu.add(this.newSqlEditorMntm);

		this.newXmlEditorMntm = new JMenuItem(new NewHtmlEditorMenuItemAction(this));
		this.newMenu.add(this.newXmlEditorMntm);

		this.newHtmlEditorMntm = new JMenuItem(new NewSQLEditorMenuItemAction(this));
		this.newMenu.add(this.newHtmlEditorMntm);

		this.OpenMntm = new JMenuItem("Open...");
		this.OpenMntm.setIcon(Icons.Small.OPEN);
		this.OpenMntm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				MainFrameView.this.openMntmActionPerformed(e);
			}
		});
		this.fileMenu.add(this.OpenMntm);

		this.saveMntm = new JMenuItem("Save");
		this.saveMntm.setIcon(Icons.Small.SAVE);
		this.saveMntm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				MainFrameView.this.saveMntmActionPerformed(arg0);
			}
		});

		this.fileMenu.add(ViewContext.getRecentFileMenu());

		this.fileMenu.add(ComponentFactory.createMenuSeparator());

		this.closeMntm = new JMenuItem(new CloseMenuItemAction());
		this.closeMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK));
		this.fileMenu.add(this.closeMntm);

		this.closeOthersMntm = new JMenuItem(new CloseOthersMenuItemAction());
		this.fileMenu.add(this.closeOthersMntm);

		this.closeAllMntm = new JMenuItem(new CloseAllMenuItemAction());
		this.closeAllMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		this.fileMenu.add(this.closeAllMntm);

		this.fileMenu.add(ComponentFactory.createMenuSeparator());
		this.saveMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));
		this.fileMenu.add(this.saveMntm);

		this.saveAsMntm = new JMenuItem(new SaveAsMenuItemAction());
		this.fileMenu.add(this.saveAsMntm);

		this.saveAllMntm = new JMenuItem("Save All");
		this.saveAllMntm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				MainFrameView.this.saveAllMntmActionPerformed(arg0);
			}
		});
		this.saveAllMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		this.fileMenu.add(this.saveAllMntm);
		this.exitMntm = new JMenuItem("Exit");
		this.exitMntm.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				MainFrameView.this.exitMntmActionPerformed(arg0);
			}
		});

		this.fileMenu.add(ComponentFactory.createMenuSeparator());

		this.reloadMntm = new JMenuItem(new ReloadMenuItemAction());
		this.reloadMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F5, 0));
		this.fileMenu.add(this.reloadMntm);

		this.openFileLocationMntm = new JMenuItem(MainFrameActionFactory.fetchOpenFileLocationMenuItemAction());
		this.fileMenu.add(this.openFileLocationMntm);

		this.filePropertiesMntm = new JMenuItem(new FilePropertyMenuItemAction());
		this.filePropertiesMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_1, InputEvent.CTRL_MASK));
		this.fileMenu.add(this.filePropertiesMntm);

		this.fileMenu.add(ComponentFactory.createMenuSeparator());

		this.fileMenu.add(this.exitMntm);

		return this.fileMenu;
	}

	/**
	 * 创建编辑菜单
	 * @return
	 */
	private JMenu createEditMenu(){

		this.editMenu = new JideMenu("Edit");
		this.menuBar.add(this.editMenu);

		this.undoMntm = new JMenuItem(new UndoMenuItemAction());
		this.undoMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_MASK));
		this.editMenu.add(this.undoMntm);

		this.redoMntm = new JMenuItem(new RedoMenuItemAction());
		this.redoMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK));
		this.editMenu.add(this.redoMntm);

		this.editMenu.add(ComponentFactory.createMenuSeparator());

		this.copyMntm = new JMenuItem(MainFrameActionFactory.fetchCopyMenuItemAction());
		this.copyMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK));
		this.editMenu.add(this.copyMntm);

		this.copyAsRtfMntm = new JMenuItem(MainFrameActionFactory.fetchCopyAsRtfMenuItemAction());
		this.editMenu.add(this.copyAsRtfMntm);

		this.cutMntm = new JMenuItem(MainFrameActionFactory.fetchCutMenuItemAction());
		this.cutMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
		this.editMenu.add(this.cutMntm);

		this.pasteMntm = new JMenuItem(MainFrameActionFactory.fetchPasteMenuItemAction());
		this.pasteMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
		this.editMenu.add(this.pasteMntm);

		this.editMenu.add(ComponentFactory.createMenuSeparator());

		this.selectAllMntm = new JMenuItem(MainFrameActionFactory.fetchSelectAllMenuItemAction());
		this.selectAllMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK));
		this.editMenu.add(this.selectAllMntm);

		this.deleteMntm = new JMenuItem(MainFrameActionFactory.fetchDeleteMenuItemAction());
		this.editMenu.add(this.deleteMntm);

		this.clearMntm = new JMenuItem(MainFrameActionFactory.fetchClearMenuItemAction());
		this.clearMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		this.editMenu.add(this.clearMntm);

		this.editMenu.add(ComponentFactory.createMenuSeparator());

		this.gotoLineMntm = new JMenuItem(MainFrameActionFactory.fetchGotoLineMenuItemAction());
		this.editMenu.add(this.gotoLineMntm);
		
		this.findNextMntm = new JMenuItem(MainFrameActionFactory.fetchFindNextMenuItemAction());
		this.editMenu.add(this.findNextMntm);

		this.findPreMntm = new JMenuItem(MainFrameActionFactory.fetchFindPreviousMenuItemAction());
		this.editMenu.add(this.findPreMntm);

		this.findAndReplaceMntm = new JMenuItem(new FindAndReplaceMenuItemAction(this));
		this.findAndReplaceMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK));
		this.editMenu.add(this.findAndReplaceMntm);

		this.editMenu.add(ComponentFactory.createMenuSeparator());

		this.insertMenu = new JMenu("Insert");
		this.editMenu.add(this.insertMenu);

		this.insertDtmMntm = new JMenuItem(MainFrameActionFactory.fetchInsertDateMenuItemAction());
		this.insertDtmMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_SEMICOLON, InputEvent.CTRL_MASK));
		this.insertMenu.add(this.insertDtmMntm);

		this.changeMenu = new JMenu("Change");
		this.editMenu.add(this.changeMenu);

		this.toUpperCaseMntm = new JMenuItem(MainFrameActionFactory.fetchUpperCaseMenuItemAction());
		this.toUpperCaseMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		this.changeMenu.add(this.toUpperCaseMntm);

		this.toLowerCaseMntm = new JMenuItem(MainFrameActionFactory.fetchLowerCaseMenuItemAction());
		this.toLowerCaseMntm.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK));
		this.changeMenu.add(this.toLowerCaseMntm);

		this.invertCaseMntm = new JMenuItem(MainFrameActionFactory.fetchInvertCaseMenuItemAction());
		this.changeMenu.add(this.invertCaseMntm);

		this.changeMenu.add(ComponentFactory.createMenuSeparator());

		this.toUnicodeTagMntm = new JMenuItem(MainFrameActionFactory.fetchToUnicodeMenuItemAction());
		this.changeMenu.add(this.toUnicodeTagMntm);

		this.fromUnicodeMntm = new JMenuItem(MainFrameActionFactory.fetchFromUnicodeMenuItemAction());
		this.changeMenu.add(this.fromUnicodeMntm);

		this.formatMenu = new JMenu("Format");
		this.editMenu.add(this.formatMenu);

		this.formatMenu.add(MainFrameActionFactory.fetchTrimEndOfLineMenuItemAction());
		this.formatMenu.add(MainFrameActionFactory.fetchFixLineToMaxMenuItemAction());


		return this.editMenu;
	}

	/**
	 * 创建视图菜单
	 * @return
	 */
	private JMenu createViewMenu(){

		this.viewMenu = new JideMenu("View");

		this.viewMenu.add(ViewContext.getToolbarMenu());

		this.stateBarCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchStateBarVisibleMenuItemAction());
		this.stateBarCkmntm.setSelected(this.viewSettings.isStateBarVisible());
		this.viewMenu.add(this.stateBarCkmntm);

		this.libraryViewCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchToggleLibraryPaneVisibleMenuItemAction());
		this.libraryViewCkmntm.setSelected(this.viewSettings.getShowLibraryView());
		this.viewMenu.add(this.libraryViewCkmntm);
		
		this.viewMenu.add(new JPopupMenu.Separator());

		this.lineNumberCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchLineNumberVisibleMenuItemAction());
		this.lineNumberCkmntm.setSelected(this.viewSettings.isLineNumberVisible());
		this.viewMenu.add(this.lineNumberCkmntm);

		this.lineWrapCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchLineWrapMenuItemAction());
		this.lineWrapCkmntm.setSelected(this.viewSettings.isLineWrap());
		this.viewMenu.add(this.lineWrapCkmntm);

		this.whiteSpaceVisibleCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchWhiteSpaceVisibleMenuItemAction());
		this.whiteSpaceVisibleCkmntm.setSelected(this.viewSettings.isWhiteSpaceVisible());
		this.viewMenu.add(this.whiteSpaceVisibleCkmntm);

		this.eolMarkersVisibleCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchEOLMarkersVisibleMenuItemAction());
		this.eolMarkersVisibleCkmntm.setSelected(this.viewSettings.isEOLMarkVisible());
		this.viewMenu.add(this.eolMarkersVisibleCkmntm);

		this.secondaryHighlightCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchSecondaryHighlightMenuItemAction());
		this.secondaryHighlightCkmntm.setSelected(this.viewSettings.isHeightLightSecondaryLanguage());
		this.viewMenu.add(this.secondaryHighlightCkmntm);

		this.markOccurrencesCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchMarkOccurrencesMenuItemAction());
		this.markOccurrencesCkmntm.setSelected(this.viewSettings.isMarkOccurrences());
		this.viewMenu.add(this.markOccurrencesCkmntm);

		this.coldFoldingCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchCodeFoldingMenuItemAction());
		this.coldFoldingCkmntm.setSelected(this.viewSettings.isCodeFoldingEnabled());
		this.viewMenu.add(this.coldFoldingCkmntm);

		this.hyperlinksCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchHyperlinkMenuItemAction());
		this.hyperlinksCkmntm.setSelected(this.viewSettings.isHyperlinksEnabled());
		this.viewMenu.add(this.hyperlinksCkmntm);

		this.autoIndentCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchAutoIndentMenuItemAction());
		this.autoIndentCkmntm.setSelected(this.viewSettings.isAutoIndentEnabled());
		this.viewMenu.add(this.autoIndentCkmntm);

		this.closeCurlyBracesCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchCloseCurlyBracesMenuItemAction());
		this.closeCurlyBracesCkmntm.setSelected(this.viewSettings.isCloseCurlyBraces());
		this.viewMenu.add(this.closeCurlyBracesCkmntm);

		this.closeMarkupTagsCkmntm = new JCheckBoxMenuItem(MainFrameActionFactory.fetchCloseMarkupTagsMenuItemAction());
		this.closeMarkupTagsCkmntm.setSelected(this.viewSettings.isCloseMarkupTags());
		this.viewMenu.add(this.closeMarkupTagsCkmntm);

		this.viewMenu.add(new JPopupMenu.Separator());

		this.editorFontMntm = new JMenuItem(MainFrameActionFactory.fetchEditorFontSetupMenuItemAction());
		this.viewMenu.add(this.editorFontMntm);

		return this.viewMenu;
	}

	private ViewSettings viewSettings = Settings.getSettings().getViewSettings();

	private LibraryPane libraryPane;
	
	private ClosableTabbedPane contentPane;
	private JideMenu fileMenu;
	private JideMenu newMenu;
	private JMenuItem OpenMntm;
	private JMenuItem saveMntm;
	private JMenuBar menuBar;
	private JMenuItem plainTextMutm;
	private JToolBar toolbar;
	private JMenuItem closeMntm;
	private JMenuItem closeAllMntm;
	private JMenuItem saveAsMntm;
	private JMenuItem saveAllMntm;
	private JMenuItem exitMntm;
	private JideMenu viewMenu;
	private JideMenu editMenu;
	private JideMenu toolsMenu;
	private JideMenu favoriteMenu;
	private JideMenu helpMenu;
	private JideSplitButton newMenuBtn;
	private JMenuItem newJavaEditorMntm;
	private JMenuItem newSqlEditorMntm;
	private JMenuItem newXmlEditorMntm;
	private JMenuItem newHtmlEditorMntm;
	private JMenuItem findAndReplaceMntm;
	private JMenuItem newPlainTextMntm;
	private JMenuItem newJavaMntm;
	private JMenuItem newXmlMntm;
	private JMenuItem newHtmlMntm;
	private JMenuItem newSqlMntm;
	private JMenuItem closeOthersMntm;
	private JideButton openBtn;
	private JideButton saveBtn;
	private JMenuItem undoMntm;
	private JMenuItem redoMntm;
	private JMenuItem reloadMntm;
	private JMenuItem filePropertiesMntm;
	private JMenuItem aboutMntm;
	private JMenuItem copyMntm;
	private JMenuItem pasteMntm;
	private JMenuItem clearMntm;
	private JMenuItem cutMntm;
	private JMenuItem copyAsRtfMntm;
	private JMenuItem openFileLocationMntm;
	private JMenuItem deleteMntm;
	private JMenuItem selectAllMntm;
	private JMenuItem findPreMntm;
	private JMenuItem gotoLineMntm;
	private JMenuItem findNextMntm;
	private JMenu insertMenu;
	private JMenu changeMenu;
	private JMenu formatMenu;
	private JMenuItem insertDtmMntm;
	private JMenuItem toUpperCaseMntm;
	private JMenuItem toLowerCaseMntm;
	private JMenuItem invertCaseMntm;
	private JMenuItem toUnicodeTagMntm;
	private JMenuItem fromUnicodeMntm;
	private JMenuItem editorFontMntm;
	private JMenuItem updateLogsMntm;
	// View Menu Items
	private JCheckBoxMenuItem stateBarCkmntm;
	private JCheckBoxMenuItem libraryViewCkmntm;
	private JCheckBoxMenuItem lineNumberCkmntm;
	private JCheckBoxMenuItem lineWrapCkmntm;
	private JCheckBoxMenuItem whiteSpaceVisibleCkmntm;
	private JCheckBoxMenuItem eolMarkersVisibleCkmntm;
	private JCheckBoxMenuItem secondaryHighlightCkmntm;
	private JCheckBoxMenuItem markOccurrencesCkmntm;
	private JCheckBoxMenuItem coldFoldingCkmntm;
	private JCheckBoxMenuItem hyperlinksCkmntm;
	private JCheckBoxMenuItem autoIndentCkmntm;
	private JCheckBoxMenuItem closeCurlyBracesCkmntm;
	private JCheckBoxMenuItem closeMarkupTagsCkmntm;
	// View Menu Items End
}
